<?php


class WSB_View_Helper_FormSelectPage extends Zend_View_Helper_FormSelect
{

	private $_options;

	public function formSelectPage($name, $value = null, $attribs = null, $listsep = "<br />\n")
	{
		$info = $this->_getInfo($name, $value, $attribs, null, $listsep);
        extract($info); // name, id, value, attribs, options, listsep, disable

		$this->_options = array();
		$this->_options[0] = '';
		$tree = WSB_Node_Page::getTree();
		$this->_buildOptions($tree);
      	$element = $this->formSelect($name, $value, $attribs, $this->_options, $listsep);
		return $element;
	}

	/**
	 * Rekursive Methode!
	 *
	 * @param WSB_Node $node
	 */
	private function _buildOptions(WSB_Node_Page $node)
	{
		if($node->IsRoot()) {
			$this->_options[$node->getPageId()] = $node->title;
		}
		foreach($node->getChildren() AS $child) {
			$this->_options[$child->getPageId()] = $child->title;
			if($child->hasChildren()) {
				$this->_buildOptions($child);
			}
		}
	}

}
